from typing import Dict

from django.core.cache import cache

from djco.base.base import Base


class BaseApi(Base):
    """
    接口专用api
    """

    @staticmethod
    def login_info(id: int):
        """
        登录者信息
        :param request:
        """
        data = cache.get("_login_info_" + str(id))
        if data:
            return data
        else:
            return BaseApi.api_ajax_error({}, '请重新登录')
        pass

    @staticmethod
    def cache_login_info(data: Dict, expire=18600):
        if data.get('id'):
            cache.set("_login_info_" + str(data.get("id")), data, expire)
        else:
            BaseApi.api_ajax_error({}, "data中必须包含id")
